<?php
namespace home\model;
use framework\core\Model;
class CategoryModel extends Model{
    protected $login_table="ask_question";
//        实现查询所有问题的方法
    public function getAllQuestions(){
        $sql="select u.username,u.user_pic ,q.*,c.cat_name from ask_question 
as q left join ask_user as u on q.user_id=u.user_id left join ask_category 
as c on q.cat_id=c.cat_id";
        return $this->dao->fetchAll($sql);
    }
    //查询数据表的总条数
    public function getTotalRows(){
        $sql="select count(*) as total from $this->true_table";
        return $this->dao->fetchOne($sql);
    }
    public function getHotUsers(){
        $sql="select u.username,u.user_pic,count(q.question_id) as num from ask_user as u 
left join ask_question as q  on u.user_id=q.user_id group by q.user_id order by num desc limit 3";
        return $this->dao->fetchAll($sql);
    }
}